﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.Master" AutoEventWireup="true" CodeBehind="jobsdtail.aspx.cs" Inherits="WebChamCong.jobsdtail" %>

<asp:Content ID="Content1" ContentPlaceHolderID="page_title" runat="server">
Chi Tiết Nhân Viên
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content_header" runat="server">

Thông Tin Nhân Viên : <asp:Label ID="txttennv" runat="server" Text="Label"></asp:Label>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="content" runat="server">
   <table cellpadding="0" cellspacing="0" border="1" width="100%">
   <tr>
   <td colspan="4" align="right">Bộ phận :</td>
   <td colspan="12"><asp:Label ID="txtbophan" runat="server" Text="Chưa cập nhật"></asp:Label></td>
   </tr>
    <tr>
   <td colspan="4" align="right">Ngày Tính Công :</td>
   <td colspan="12"><asp:Label ID="txtngaycong" runat="server" Text="Chưa cập nhật"></asp:Label></td>
   </tr>
   <tr>
   <td>STT</td>
   <td>Ca</td>
   <td>Giờ vào</td>
   <td>Giờ Về</td>
   <td>Giờ ra trưa </td>
   <td>Giờ vào trưa</td>
   <td>TG ăn trưa</td>
   <td>Giờ ra tối</td>
   <td>Giờ vào tối</td>
   <td>TG ăn tối</td>
   <td>TG ra ngoài</td>
   <td>Làm trể</td>
   <td>Về sớm</td>
   <td>Ăn Trể</td>
   <td>Giờ Chuẩn</td>
   <td>Giờ Thực Tế</td>
   </tr>
   <%
       Double tongTGAnTrua = 0;
       Double tongTGAnToi = 0;
       Double tongTGDiTre = 0;
       Double tongTGDiSom = 0;
       Double tongTGAnTre = 0;
       Double tongGioLam = 0;
       Double tgLamChuan = 0;
       int id = int.Parse(Request.QueryString["id"]);
       int month = int.Parse(Request.QueryString["month"]);
       DTO.WitSchedule ds = BUS.LichBUS.getScheduleByUserID(id,month);
       for (int i = ds.StartTime.Day; i <= ds.EndTime.Day; i++)
       {
           int value = 0;
           switch (i)
           {
               case 1:
                   value = ds.Day1; break;
               case 2:
                   value = ds.Day2; break;
               case 3:
                   value = ds.Day3; break;
               case 4:
                   value = ds.Day4; break;
               case 5:
                   value = ds.Day5; break;
               case 6:
                   value = ds.Day6; break;
               case 7:
                   value = ds.Day7; break;
               case 8:
                   value = ds.Day8; break;
               case 9:
                   value = ds.Day9; break;
               case 10:
                   value = ds.Day10; break;
               case 11:
                   value = ds.Day11; break;
               case 12:
                   value = ds.Day12; break;
               case 13:
                   value = ds.Day13; break;
               case 14:
                   value = ds.Day14; break;
               case 15:
                   value = ds.Day15; break;
               case 16:
                   value = ds.Day16; break;
               case 17:
                   value = ds.Day17; break;
               case 18:
                   value = ds.Day18; break;
               case 19:
                   value = ds.Day19; break;
               case 20:
                   value = ds.Day20; break;
               case 21:
                   value = ds.Day21; break;
               case 22:
                   value = ds.Day22; break;
               case 23:
                   value = ds.Day23; break;
               case 24:
                   value = ds.Day24; break;
               case 25:
                   value = ds.Day25; break;
               case 26:
                   value = ds.Day26; break;
               case 27:
                   value = ds.Day27; break;
               case 28:
                   value = ds.Day28; break;
               case 29:
                   value = ds.Day29; break;
               case 30:
                   value = ds.Day30; break;
               case 31:
                   value = ds.Day31; break;
           }
           double result=0;
           Double MinuLate = 0;
           Double Stoi = 0;
           Double MinuEarly = 0;
           double result2=0;
           Double tg = 0;
           Double Late=0;
           Double Early=0;
           Double EatLate = 0;
           int gioihan=11;
           int gioihan1=18;
           string tenca = BUS.LichBUS.GetShiftCodeByID(value);
           DTO.CheckDTO CheckIn = BUS.CheckBUS.GetJobByday(i, month, int.Parse(ds.StartTime.Year.ToString()), id);
            DTO.CheckDTO CheckOut = BUS.CheckBUS.GetJobBydayout(i, month, int.Parse(ds.StartTime.Year.ToString()), id);
           // lấy tổng giờ ra ngoài ăn trưa
           DTO.CheckDTO TimeMealOut = BUS.CheckBUS.GetTimeMealOut(i, month, int.Parse(ds.StartTime.Year.ToString()), id,14,11);
           DTO.CheckDTO TimeNightOut = BUS.CheckBUS.GetTimeMealOut(i, month, int.Parse(ds.StartTime.Year.ToString()), id, 20.5, 18);
           if (Convert.ToString(TimeNightOut) != "")
           {
               gioihan1 = TimeNightOut.CheckTime.TimeOfDay.Hours;
           }
           DTO.CheckDTO TimeNightIn = BUS.CheckBUS.GetTimeMeal(i, month, int.Parse(ds.StartTime.Year.ToString()), id, gioihan1, 20.5);
           if (Convert.ToString(TimeMealOut) != "")
           {
                gioihan = TimeMealOut.CheckTime.TimeOfDay.Hours;
           }
               DTO.CheckDTO TimeMeal = BUS.CheckBUS.GetTimeMeal(i, month, int.Parse(ds.StartTime.Year.ToString()), id,gioihan,  13.5);
           
           DTO.LichDTO lich = BUS.LichBUS.GetTime(value);
    %>
    <tr>
   <td><% Response.Write(i); %></td>
   <td><% 
           if (tenca != null)
           {
               Response.Write(tenca);
           }
           else
           { Response.Write("N"); }
       %></td>
   <td>
   <!--Giờ Đi Làm -->
<%
       try
       {
           // Check is null 
           if (tenca != "N")
           {
               if (Convert.ToString(CheckIn) == "")
               {
                   CheckIn = new DTO.CheckDTO(); CheckIn.CheckTime = lich.ThoigianBd;
               }
               CheckIn.CheckTime = (CheckIn.CheckTime.TimeOfDay.TotalMinutes >= lich.TimeInFrom.TimeOfDay.TotalMinutes && CheckIn.CheckTime.TimeOfDay.TotalMinutes <= lich.TimeInTo.TimeOfDay.TotalMinutes) ? CheckIn.CheckTime : lich.ThoigianBd;
               result = CheckIn.CheckTime.TimeOfDay.TotalMilliseconds - lich.ThoigianBd.TimeOfDay.TotalMilliseconds;
               string outputString = (result == 0) ? "0" : CheckIn.CheckTime.TimeOfDay.ToString();
               Response.Write(outputString);
           }
       }
       catch { } 
            

   
   %>
</td>
<td>
<!--Giờ Về-->
<%
       try
       {
           if (tenca != "N")
           {
               // Check is null 
               if (Convert.ToString(CheckOut) == "")
               {
                   CheckOut = new DTO.CheckDTO();
                   CheckOut.CheckTime = lich.ThoigianKT;
               }
               CheckOut.CheckTime = (CheckOut.CheckTime.TimeOfDay.TotalMinutes >= lich.TimeOutFrom.TimeOfDay.TotalMinutes && CheckOut.CheckTime.TimeOfDay.TotalMinutes <= lich.TimeOutTo.TimeOfDay.TotalMinutes) ? CheckOut.CheckTime : lich.ThoigianKT;

               result2 = lich.ThoigianKT.TimeOfDay.TotalMilliseconds - CheckOut.CheckTime.TimeOfDay.TotalMilliseconds;

               string outputString = (result2 == 0) ? "0" : CheckOut.CheckTime.TimeOfDay.ToString();

               Response.Write(outputString); 
           }

       }
       catch { } 

   %>
   </td>
<td>
<!--Giờ ra ăn trưa-->
<%
    try 
    {
        if (tenca != "N")
        {
            Response.Write(TimeMealOut.CheckTime.TimeOfDay); 
        }
    }
    catch { }
    
 %>
</td>
<td>
<!--Giờ ăn cơm xong-->
<%
       try 
       {
           if (tenca != "N")
           {
               Response.Write(TimeMeal.CheckTime.TimeOfDay); 
           }
       }
       catch { } 
%>
   </td>
   <td>
<!------------------------------Thoi gian an trua------------------------------------------>
<%
       try 
       {
           
           if (tenca == "N")
           {
               tg = 0;
           }
           else
           {
               if (Convert.ToString(TimeMeal) == "" || Convert.ToString(TimeMealOut) == "")
               {
                   tg = 0;
               }
               else
               {
                   Double outTime = Math.Round(TimeMeal.CheckTime.TimeOfDay.TotalMinutes - TimeMealOut.CheckTime.TimeOfDay.TotalMinutes);
                   tg = outTime;

               }
           }
           tongTGAnTrua += tg;
           Response.Write(tg);
       }
       catch { }
           
   %>
</td>
<td>
<!-- Giờ ra ăn tối -->
<%
       Double gioantoi = 0;
       try 
       {
           if (tenca == "N")
           {
               Response.Write("");
           }
           else
           {
               if (tenca != "X" && tenca !="C")
               {

               }
               else
               {
                   if (Convert.ToString(TimeNightOut) != "")
                   {
                       Response.Write(TimeNightOut.CheckTime.TimeOfDay);
                       gioantoi = TimeNightOut.CheckTime.TimeOfDay.TotalMinutes;
                   }
                   else
                   {
                       Response.Write("");
                       gioantoi = 0;
                   }  
               }
           }
       }
       catch { } 
   %>
</td>
<td>
<!-- Giờ vào ăn Tối -->
<%
           
       Double gioratoi = 0;
       try 
       {
           if (tenca == "N")
           {
               Response.Write("");
           }
           else
           {
               if (Convert.ToString(TimeNightIn) != "")
               {
                   Response.Write(TimeNightIn.CheckTime.TimeOfDay);
                   gioratoi = TimeNightIn.CheckTime.TimeOfDay.TotalMinutes;

               }
               else
               {
                   Response.Write("");
                   gioratoi = 0;
               }
           }
       }
       catch { } 
   %>
</td>
<td>
<!--Thời gian ăn tối-->
<%
       try 
       {
           if (tenca == "N")
           {
               Response.Write("");
               
           }
           else
           {
               if (Convert.ToString(TimeNightIn) == "" || Convert.ToString(TimeNightOut) == "")
               {
                   Stoi = 0;
               }
               else
               {
                   Stoi = Math.Round(TimeNightIn.CheckTime.TimeOfDay.TotalMinutes - TimeNightOut.CheckTime.TimeOfDay.TotalMinutes); 
               }
           }
           tongTGAnToi += Stoi;
           Response.Write(Stoi);
       }
       catch { }
    %>
</td>
<td>
<!--Thời Gian Ra ngoài-->
<%
       try  {
           if (tenca != "N")
           {
              
           }
       }
       catch { }
   %>
</td>
<td>
<!--Thời gian đi trể tính theo phút-->
<%
       try 
       {
           if (tenca != "N")
           {
               //Thời gian trể
               Late = CheckIn.CheckTime.TimeOfDay.TotalMinutes - lich.ThoigianBd.TimeOfDay.TotalMinutes;
               if (Late > 0)
               {
                   MinuLate = Late;
                   tongTGDiTre += Math.Round(Late);
                   Response.Write(Math.Round(Late));
               } 
           }
       }
       catch { }          
   %>
</td>
<td>
   <!-- Thời gian đi sớm-->
   <% 
       if (tenca != "N")
       {
           Early = lich.ThoigianKT.TimeOfDay.TotalMinutes - CheckOut.CheckTime.TimeOfDay.TotalMinutes;
           if (Early > 0)
           {
               MinuEarly = Early;
               tongTGDiSom += Math.Round(Early);
               Response.Write(Math.Round(Early));
           }  
       }
       
   %>
   </td>
<td>
<!--Giờ ăn trể-->
<%
       if (tenca == "N")
       {
           Response.Write("");
       }
       else
       {
           if (tenca == "X")
           {
               if (((tg + Stoi) - 60) > 0)
               {

                   EatLate = Math.Round((tg + Stoi) - 60);
                   tongTGAnTre += EatLate;
                   Response.Write(Math.Round((tg + Stoi) - 60));
               }

           }
           else
           {
               if ((tg - 60) > 0)
               {
                   EatLate = Math.Round(tg - 60);
                   tongTGAnTre += EatLate;
                   Response.Write(Math.Round(tg - 60));
               }

           }   

       }
   %>
</td>
<td>
<!--Giờ Làm việc chuẩn-->
<%
       try 
        {
            if (result == 0 && result2 == 0)
           {
               Response.Write(0);
           }
           else
            {
                tgLamChuan += Math.Round((Double)lich.TimeWork/60,2);
                Response.Write((Double)lich.TimeWork / 60);
            }
           
        }
       catch 
       { } 
   %>
</td>
<td>
<!--Giờ Làm thực tế-->
<%
       try
       {
           Double GioLam = 0;
           Double GioLamThuc = (CheckOut.CheckTime.TimeOfDay.TotalMinutes - CheckIn.CheckTime.TimeOfDay.TotalMinutes) / 60;
           Double GioViPham = (MinuEarly + MinuLate + EatLate) / 60;
           if (tenca == "N")
           {
               Response.Write("");
           }
           else
           {
               if (result == 0 && result2 == 0)
               {
                   GioLam=0;
               }
               else
               {
                   if (result != 0 && result2 != 0)
                   {
                       GioLam = ((Double)lich.TimeWork / 60) - GioViPham;
                   }
                   else
                   {
                       if (GioLamThuc >= (Double)lich.TimeWork / 60)
                       {
                           GioLam = ((Double)lich.TimeWork / 60) - GioViPham;
                       }

                   }
               }
               
           }
           tongGioLam += GioLam;
           Response.Write(Math.Round( GioLam,2));
       }
       catch 
       { }
   %>
</td>
</tr>    
<%     
    
       }     
   %>
<tr>
<td colspan="6" align="right" >Tổng Cộng :</td>
<td>
<!--Tổng thời gian ăn trưa-->
<% 
       Response.Write(tongTGAnTrua);
   %>
</td>
<td colspan="2"></td>
<td>
<!--Tổng thời gian ăn tối-->
<%
       Response.Write(tongTGAnToi); 
   %>
   </td>
   <!--Tổng thời gian đi ra ngoài-->
   <td></td>
   <td>
   <!--Tổng thời gian đi trể-->
    <%
        Response.Write(tongTGDiTre);
     %>
   </td>
   <td>
   <!--Tổng thời gian về sớm -->
   <%
       Response.Write(tongTGDiSom); 
   %>
   </td>
   <td><!--Tổng thời gian ăn trể-->
   <%
       Response.Write(tongTGAnTre); 
   %>
   </td>
   <td>
   <!--Tổng thời gian làm Chuẩn-->
   <%
       Response.Write(tgLamChuan); 
   %>
   </td>
   <td>
   <!--Tổng thời gian giờ làm-->
   <%
       Response.Write(Math.Round( tongGioLam,2)); 
   %>
   </td>
   </tr>
    <tr>
   <td colspan="4" align="right">Ghi Chú Các lổi vi phạm :</td>
   <td colspan="12">
   <ul>
   <li>Quên CheckIn , CheckOut hoặc không Check</li>
   <li>Quên CheckIn , CheckOut giờ ăn trưa </li>
   <li>Ăn Cơm quá giờ qui định </li>
   <li>Đi trể quá 1 tiếng</li>
   <li>Về sớm không quá 1 tiêng</li>
   </ul>
   </td>
   </tr>
   </table>
  
</asp:Content>
